import psycopg2

DATABASE = dict(
    database="data",
    user="yufuxiao",
    password="Citory2021YFX",
    host="ai.cityface.tech",
    port="32768",
    options="-c search_path=spider_data"
)


def db_insert(title, data, content, image_url=None, image_name=None):
    conn = psycopg2.connect(**DATABASE)

    cur = conn.cursor()

    # sql = "INSERT INTO  gzspider_hangzhou_zcfg_spider(title, date, content) VALUES ('{}','{}','{}')".format(title, data, content)
    # sql = "INSERT INTO  gzspider_hangzhou_file_spider(title, date, content, image_url,image_name) VALUES ('{}','{}','{}','{}','{}')".format(
    #     title, data, content, image_url, image_name)
    sql = "INSERT INTO  gzspider_hangzhou_ghxm_spider(title, date, content) VALUES ('{}','{}','{}')".format(title, data, content)
    cur.execute(sql)

    conn.commit()
    conn.close()


if __name__ == '__main__':
    db_insert('ascavs', 'ascasc', 'cascas')
